<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        .title{
            width: 100%;
            height: 40px;
        }
        .title>ul{
            width: 500px;
            height: 40px;
            margin: 0 auto;
        }
        .title>ul>li{
            float: left;
            list-style-type: none;
            margin: 0 20px;
            height: 40px;
            line-height: 40px;
        }
        .title>ul>li:hover{
            cursor: pointer;
        }
        .cotanin{
            height: 300px;
            width: 500px;
            margin: 0 auto;
        }
        .oncl{
            background-color: red;
            color: white;
        }
        .lost{
            display:none;
        }
    </style>
</head>
<body>
    <div>
        <div class="title">
            <ul>
                <li class="oncl">我是sb1</li>
                <li>我是sb2</li>
                <li>我是sb3</li>
                <li>我是sb4</li>
            </ul>
        </div>
        <div class="cotanin">
            <div>我是傻逼1的内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente distinctio reprehenderit voluptatem quam at voluptate atque neque provident fugit amet.</div>
            <div class="lost">我是傻逼2的内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente distinctio reprehenderit voluptatem quam at voluptate atque neque provident fugit amet.</div>
            <div class="lost">我是傻逼3的内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente distinctio reprehenderit voluptatem quam at voluptate atque neque provident fugit amet.</div>
            <div class="lost">我是傻逼4的内容Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente distinctio reprehenderit voluptatem quam at voluptate atque neque provident fugit amet.</div>
        </div>
    </div>
    <script>
        var title_li = document.querySelector('.title').querySelector('ul').querySelectorAll('li');
        var cotanin_div = document.querySelector('.cotanin').querySelectorAll('div');
        for(var i = 0;i < title_li.length ; i++){
            title_li[i].setAttribute('index',i);        //添加索引链接
            title_li[i].onclick = function () {
                for(var j=0 ; j < title_li.length ; j++){
                    title_li[j].className='';
                }
                this.className = 'oncl';
                var s = this.getAttribute('index');
                cotanin_div[s].style.display ='block';
                for(var l=0; l < cotanin_div.length ; l++){
                    if(l != s){
                        cotanin_div[l].style.display ='none';
                    }
                }
            }
        }
    </script>
</body>
</html>